package com.gongguizhijia.Util;

import com.alibaba.excel.EasyExcel;
import com.gongguizhijia.Constant.Constants;
import com.gongguizhijia.listen.CommonListen;
import com.gongguizhijia.pojo.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Chenglei
 * @date 2021/6/2 9:06
 */
public class ImportExcel {

    /**
     * 导入Excel数据
     */
    public static Map<String,List> importExcel() throws FileNotFoundException {
        Map<String,List> map =  new HashMap<>();

        //导入 cv_ecu_config_info 表
        File file1 = new File("src\\file\\cv_ecu_config_info.xlsx");
        FileInputStream fileInputStream1 = new FileInputStream(file1);
        CommonListen<CvEcuConfigInfo> commonListen1 = new CommonListen<CvEcuConfigInfo>(CvEcuConfigInfo.class);
        EasyExcel.read(fileInputStream1, CvEcuConfigInfo.class, commonListen1).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuConfigInfo> listConfigInfo = commonListen1.getList();
        map.put(Constants.LIST_CONFIG_INFO,listConfigInfo);
        // 打印所有导入的数据
        //listConfigInfo.forEach(System.out::println);

        //导入 cv_ecu_conversion 表
        File file2 = new File("src\\file\\cv_ecu_conversion.xlsx");
        FileInputStream fileInputStream2 = new FileInputStream(file2);
        CommonListen<CvEcuConversion> commonListen2 = new CommonListen<CvEcuConversion>(CvEcuConversion.class);
        EasyExcel.read(fileInputStream2, CvEcuConversion.class, commonListen2).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuConversion> listConversion = commonListen2.getList();
        map.put(Constants.LIST_CONVERSION,listConversion);
        // 打印所有导入的数据
        //listConversion.forEach(System.out::println);

        //导入 cv_ecu_conversion_detail 表
        File file3 = new File("src\\file\\cv_ecu_conversion_detail.xlsx");
        FileInputStream fileInputStream3 = new FileInputStream(file3);
        CommonListen<CvEcuConversionDetail> commonListen3 = new CommonListen<CvEcuConversionDetail>(CvEcuConversionDetail.class);
        EasyExcel.read(fileInputStream3, CvEcuConversionDetail.class, commonListen3).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuConversionDetail> listConversionDetail = commonListen3.getList();
        map.put(Constants.LIST_CONVERSION_DETAIL,listConversionDetail);
        // 打印所有导入的数据
        //listConversionDetail.forEach(System.out::println);

        //导入 cv_ecu_dtc 表
        File file4 = new File("src\\file\\cv_ecu_dtc.xlsx");
        FileInputStream fileInputStream4 = new FileInputStream(file4);
        CommonListen<CvEcuDtc> commonListen4 = new CommonListen<CvEcuDtc>(CvEcuDtc.class);
        EasyExcel.read(fileInputStream4, CvEcuDtc.class, commonListen4).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuDtc> listDtc = commonListen4.getList();
        map.put(Constants.LIST_DTC,listDtc);
        // 打印所有导入的数据
        //listDtc.forEach(System.out::println);

        //导入 cv_ecu_id 表
        File file5 = new File("src\\file\\cv_ecu_id.xlsx");
        FileInputStream fileInputStream5 = new FileInputStream(file5);
        CommonListen<CvEcuId> commonListen5= new CommonListen<CvEcuId>(CvEcuId.class);
        EasyExcel.read(fileInputStream5, CvEcuId.class, commonListen5).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuId> listID = commonListen5.getList();
        map.put(Constants.LIST_ID,listID);
        // 打印所有导入的数据
        //listID.forEach(System.out::println);

        //导入 cv_ecu_mntsignal 表
        File file6 = new File("src\\file\\cv_ecu_mntsignal.xlsx");
        FileInputStream fileInputStream6 = new FileInputStream(file6);
        CommonListen<CvEcuMntsignal> commonListen6= new CommonListen<CvEcuMntsignal>(CvEcuMntsignal.class);
        EasyExcel.read(fileInputStream6, CvEcuMntsignal.class, commonListen6).sheet().doRead();
        // 获取导入的数据集合
        List<CvEcuMntsignal> listMntsignal = commonListen6.getList();
        map.put(Constants.LIST_MNTSIGNAL,listMntsignal);
        // 打印所有导入的数据
        //listMntsignal.forEach(System.out::println);

        //导入 system_map_ecu_id 表
        File file7 = new File("src\\file\\system_map_ecu_id.xlsx");
        FileInputStream fileInputStream7 = new FileInputStream(file7);
        CommonListen<SystemMapEcuId> commonListen7= new CommonListen<SystemMapEcuId>(SystemMapEcuId.class);
        EasyExcel.read(fileInputStream7, SystemMapEcuId.class, commonListen7).sheet().doRead();
        // 获取导入的数据集合
        List<SystemMapEcuId> listSystemMapEcuId = commonListen7.getList();
        map.put(Constants.LIST_SYSTEM_ECU_ID,listSystemMapEcuId);
        // 打印所有导入的数据
        //listMntsignal.forEach(System.out::println);

        //返回数据
        return map;
    }


}
